// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Text;
using System.Xml;

using QuoteAdvantage.CrmSdk;

namespace QuoteAdvantage
{
	/// <summary>
	/// Summary description for Product.
	/// </summary>
	public class Organization
	{
      private Guid      m_guidOrganizationId;
      private string    m_strCurrencySymbol;
      private int       m_nCurrencyFormatCode;

		public Organization()
		{
			
		}     
      
      public Guid OrganizationId
      {
         get { return m_guidOrganizationId;}
         set { m_guidOrganizationId = value;}
      }

      public string CurrencySymbol
      {
         get { return m_strCurrencySymbol;}
         set { m_strCurrencySymbol = value;}
      }
      
      public int CurrencyFormatCode
      {
         get { return m_nCurrencyFormatCode;}
         set { m_nCurrencyFormatCode = value;}
      }
                           
      /*
       Sample XML
        */
      public void LoadFromXml(string xmlData)
      {
         XmlDocument    doc = new XmlDocument();

         doc.LoadXml(xmlData);
         XmlNode     nodeRoot = doc.DocumentElement;
         LoadFromXmlNode(nodeRoot);
      }

      /*
       Sample XML
       
"<resultset morerecords='0' paging-cookie='$1$$organization$organizationid$1$0$38${3700B581-EF88-4546-B948-8AA59A58A21F}$!$organization$organizationid$1$0$38${3700B581-EF88-4546-B948-8AA59A58A21F}$'>
<result>
   <organizationid>{3700B581-EF88-4546-B948-8AA59A58A21F}</organizationid>
   <name>ACME</name>
   <usergroupid>{747F04BC-CE17-4236-B51B-C17EFB1B00CE}</usergroupid>
   <privilegeusergroupid>{D3A096A6-EDB7-449B-95A8-A4C0FCB499D0}</privilegeusergroupid>
   <fiscalperiodtype formattedvalue=\"2,002\">2002</fiscalperiodtype>
   <fiscalcalendarstart time=\"12:00 PM\" date=\"06/10/2007\">2007-06-10T12:00:00-07:00</fiscalcalendarstart>
   <dateformatcode formattedvalue=\"3\">3</dateformatcode>
   <timeformatcode formattedvalue=\"0\">0</timeformatcode>
   <currencysymbol>$</currencysymbol>
   <weekstartdaycode formattedvalue=\"0\">0</weekstartdaycode>
   <dateseparator>/</dateseparator>
   <fullnameconventioncode formattedvalue=\"1\">1</fullnameconventioncode><negativeformatcode formattedvalue=\"0\">0</negativeformatcode><numberformat>us</numberformat><isdisabled>0</isdisabled><kbprefix>KBA</kbprefix><currentkbnumber formattedvalue=\"1,056\">1056</currentkbnumber><caseprefix>CAS</caseprefix><currentcasenumber formattedvalue=\"1,015\">1015</currentcasenumber><contractprefix>CNR</contractprefix><currentcontractnumber formattedvalue=\"1,004\">1004</currentcontractnumber><quoteprefix>QUO</quoteprefix><currentquotenumber formattedvalue=\"1,004\">1004</currentquotenumber><orderprefix>ORD</orderprefix><currentordernumber formattedvalue=\"1,000\">1000</currentordernumber><invoiceprefix>INV</invoiceprefix><currentinvoicenumber formattedvalue=\"1,000\">1000</currentinvoicenumber><uniquespecifierlength formattedvalue=\"6\">6</uniquespecifierlength><createdon time=\"7:12 PM\" date=\"11/09/2006\">2006-11-09T19:12:05-08:00</createdon><modifiedon time=\"10:44 AM\" date=\"11/11/2006\">2006-11-11T10:44:23-08:00</modifiedon><fiscalyearformat>FY yyyy</fiscalyearformat><fiscalperiodformat>Q</fiscalperiodformat><fiscalyearperiodconnect>-</fiscalyearperiodconnect><languagecode formattedvalue=\"1,033\">1033</languagecode><dateformatstring>MM/dd/yyyy</dateformatstring><timeformatstring>h:mm tt</timeformatstring><pricingdecimalprecision formattedvalue=\"2\">2</pricingdecimalprecision><showweeknumber>0</showweeknumber><integrationuserid>{6212F40F-4732-462A-8D46-64EFA67FD216}</integrationuserid><reportinggroupname>MSCRM\\ReportingGroup {3700b581-ef88-4546-b948-8aa59a58a21f}</reportinggroupname>
   <tagmaxaggressivecycles formattedvalue=\"2\">2</tagmaxaggressivecycles><sharetopreviousowneronassign>0</sharetopreviousowneronassign><fiscalsettingsupdated>1</fiscalsettingsupdated><allowautounsubscribeacknowledgement>0</allowautounsubscribeacknowledgement>
   <sqlaccessgroupname>MSCRM\\SQLAccessGroup {3700b581-ef88-4546-b948-8aa59a58a21f}</sqlaccessgroupname><allowoutlookscheduledsyncs>1</allowoutlookscheduledsyncs><reportinggroupid>{A1E08B26-C123-40C6-BEDB-526420044B48}</reportinggroupid>
   <currencyformatcode formattedvalue=\"0\">0</currencyformatcode>
   <tokenexpiry formattedvalue=\"1,440\">1440</tokenexpiry><systemuserid>{C56F9350-C973-4EE2-8345-1C369E2E5823}</systemuserid><isregistered>0</isregistered>
   <sitemapxml>&lt;SiteMap&gt;&lt;Area Id=\"Workplace\" ResourceId=\"Area_Workplace\" ShowGroups=\"true\" Icon=\"/_imgs/workplace_24x24.gif\" DescriptionResourceId=\"Workplace_Description\"&gt;&lt;Group Id=\"MyWork\" ResourceId=\"Group_MyWork\" DescriptionResourceId=\"My_Work_Description\"&gt;&lt;SubArea Id=\"nav_activities\" Entity=\"activitypointer\" Url=\"/Workplace/home_activities.aspx\" /&gt;&lt;SubArea Id=\"nav_calendar\" Icon=\"/_imgs/area/18_calendar.gif\" ResourceId=\"Homepage_Calendar\" Url=\"/workplace/home_calendar.aspx\" Client=\"Web\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_queues\" Entity=\"queue\" Url=\"/workplace/home_workplace.aspx\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_answers\" Entity=\"kbarticle\" Url=\"/workplace/home_answers.aspx\"&gt;&lt;Privilege Entity=\"subject\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_reports\" Icon=\"/_imgs/area/18_reports.gif\" ResourceId=\"Homepage_Reports\" Url=\"/CRMReports/home_reports.aspx\" OutlookShortcutIcon=\"/_imgs/olk_reports.ico\" DescriptionResourceId=\"Reports_Description\" /&gt;&lt;SubArea Id=\"nav_news\" Entity=\"businessunitnewsarticle\" Url=\"/home/homepage/home_news.aspx\" /&gt;&lt;/Group&gt;&lt;Group Id=\"Customers\" ResourceId=\"Group_Customers\" DescriptionResourceId=\"Customers_Description\"&gt;&lt;SubArea Id=\"nav_accts\" Entity=\"account\" /&gt;&lt;SubArea Id=\"nav_conts\" Entity=\"contact\" /&gt;&lt;/Group&gt;&lt;Group Id=\"SFA\" 
   ResourceId=\"Area_Sales\" IsProfile=\"true\" DescriptionResourceId=\"Sales_Description\"&gt;&lt;SubArea Id=\"nav_lists1\" Entity=\"list\" /&gt;&lt;SubArea Id=\"nav_leads\" Entity=\"lead\" /&gt;&lt;SubArea Id=\"nav_oppts\" Entity=\"opportunity\" /&gt;&lt;SubArea Id=\"nav_quotes\" Entity=\"quote\" /&gt;&lt;SubArea Id=\"nav_orders\" Entity=\"salesorder\" /&gt;&lt;SubArea Id=\"nav_invoices\" Entity=\"invoice\" /&gt;&lt;/Group&gt;&lt;Group Id=\"MA\" ResourceId=\"Area_Marketing\" IsProfile=\"true\" DescriptionResourceId=\"Marketing_Description\"&gt;&lt;SubArea Id=\"nav_lists\" Entity=\"list\" /&gt;&lt;SubArea Id=\"nav_campaigns\" Entity=\"campaign\" Url=\"/MA/home_camps.aspx\" /&gt;&lt;SubArea Id=\"nav_minicamps\" ResourceId=\"Menu_Label_Mini_Campaigns\" DescriptionResourceId=\"Quick_Campaign_Description\" Icon=\"/_imgs/ico_18_minicamps.gif\" OutlookShortcutIcon=\"/_imgs/olk_4400.ico\" Url=\"/MA/home_minicamps.aspx\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;/Group&gt;&lt;Group Id=\"CS\" ResourceId=\"Area_Service\" IsProfile=\"true\" DescriptionResourceId=\"Customer_Service_Description\"&gt;&lt;SubArea Id=\"nav_cases\" Entity=\"incident\" Url=\"/CS/home_cases.aspx\" /&gt;&lt;SubArea Id=\"nav_managekb\" ResourceId=\"Homepage_KBManager\" Icon=\"/_imgs/ico_18_126.gif\" Url=\"/cs/home_managekb.aspx\" Client=\"Web\"&gt;&lt;Privilege Entity=\"kbarticle\" Privilege=\"Read,Write,Create\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_contracts\" Entity=\"contract\" /&gt;&lt;/Group&gt;&lt;Group Id=\"SM\" ResourceId=\"Area_Scheduling\" IsProfile=\"true\"&gt;&lt;SubArea Id=\"nav_apptbook\" ResourceId=\"Homepage_AppointmentBook\" Icon=\"/_imgs/ico_18_servicecal.gif\" Url=\"/sm/home_apptbook.aspx\" Client=\"Web\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;Privilege Entity=\"service\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;/Group&gt;&lt;/Area&gt;&lt;Area Id=\"SFA\" ResourceId=\"Area_Sales\" 
Icon=\"/_imgs/sales_24x24.gif\" DescriptionResourceId=\"Sales_Description\"&gt;&lt;Group Id=\"SFA\"&gt;&lt;SubArea Id=\"nav_leads\" Entity=\"lead\" /&gt;&lt;SubArea Id=\"nav_oppts\" Entity=\"opportunity\" /&gt;&lt;SubArea Id=\"nav_accts\" Entity=\"account\" /&gt;&lt;SubArea Id=\"nav_conts\" Entity=\"contact\" /&gt;&lt;SubArea Id=\"nav_lists\" 
Entity=\"list\" /&gt;&lt;SubArea Id=\"nav_comps\" Entity=\"competitor\" /&gt;&lt;SubArea Id=\"nav_products\" Entity=\"product\" /&gt;&lt;SubArea Id=\"nav_saleslit\" Entity=\"salesliterature\" /&gt;&lt;SubArea Id=\"nav_quotes\" Entity=\"quote\" /&gt;&lt;SubArea Id=\"nav_orders\" Entity=\"salesorder\" /&gt;&lt;SubArea Id=\"nav_invoices\" Entity=\"invoice\" /&gt;&lt;SubArea Id=\"nav_minicamps\" ResourceId=\"Menu_Label_Mini_Campaigns\" DescriptionResourceId=\"Quick_Campaign_Description\" Icon=\"/_imgs/ico_18_minicamps.gif\" Url=\"/MA/home_minicamps.aspx\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;/Group&gt;&lt;/Area&gt;&lt;Area Id=\"MA\" ResourceId=\"Area_Marketing\" 
   Icon=\"/_imgs/marketing_24x24.gif\" DescriptionResourceId=\"Marketing_Description\"&gt;&lt;Group Id=\"MA\"&gt;&lt;SubArea Id=\"nav_leads\" Entity=\"lead\" /&gt;&lt;SubArea Id=\"nav_accts\" Entity=\"account\" /&gt;&lt;SubArea Id=\"nav_conts\" Entity=\"contact\" /&gt;&lt;SubArea Id=\"nav_lists\" Entity=\"list\" /&gt;&lt;SubArea Id=\"nav_campaigns\" Entity=\"campaign\" Url=\"/MA/home_camps.aspx\" /&gt;&lt;SubArea Id=\"nav_products\" Entity=\"product\" /&gt;&lt;SubArea Id=\"nav_saleslit\" Entity=\"salesliterature\" /&gt;&lt;SubArea Id=\"nav_minicamps\" ResourceId=\"Menu_Label_Mini_Campaigns\" DescriptionResourceId=\"Quick_Campaign_Description\" Icon=\"/_imgs/ico_18_minicamps.gif\" Url=\"/MA/home_minicamps.aspx\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;/Group&gt;&lt;/Area&gt;&lt;Area Id=\"CS\" ResourceId=\"Area_Service\" Icon=\"/_imgs/services_24x24.gif\" DescriptionResourceId=\"Customer_Service_Description\"&gt;&lt;Group Id=\"CS\"&gt;&lt;SubArea Id=\"nav_apptbook\" ResourceId=\"Homepage_AppointmentBook\" Icon=\"/_imgs/ico_18_servicecal.gif\" Url=\"/sm/home_apptbook.aspx\" Client=\"Web\"&gt;&lt;Privilege Entity=\"activitypointer\" Privilege=\"Read\" /&gt;&lt;Privilege Entity=\"service\" Privilege=\"Read\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_cases\" Entity=\"incident\" Url=\"/CS/home_cases.aspx\" /&gt;&lt;SubArea Id=\"nav_accts\" Entity=\"account\" /&gt;&lt;SubArea Id=\"nav_contacts\" Entity=\"contact\" /&gt;&lt;SubArea Id=\"nav_managekb\" ResourceId=\"Homepage_KBManager\" Icon=\"/_imgs/ico_18_126.gif\" Url=\"/cs/home_managekb.aspx\" Client=\"Web\"&gt;&lt;Privilege Entity=\"kbarticle\" Privilege=\"Read,Write,Create\" /&gt;&lt;/SubArea&gt;&lt;SubArea Id=\"nav_contracts\" Entity=\"contract\" /&gt;&lt;SubArea Id=\"nav_products\" Entity=\"product\" /&gt;&lt;SubArea Id=\"nav_services\" 
   Entity=\"service\" /&gt;&lt;/Group&gt;&lt;/Area&gt;&lt;Area Id=\"Settings\" ResourceId=\"Area_Settings\" Icon=\"/_imgs/settings_24x24.gif\"&gt;&lt;Group Id=\"Settings\"&gt;&lt;SubArea Id=\"nav_settings\" ResourceId=\"Homepage_Settings\" Icon=\"/_imgs/area/18_settings.gif\" Url=\"/tools/home_tools.aspx\" Client=\"Web\" /&gt;&lt;SubArea Id=\"nav_syscust\" 
ResourceId=\"Homepage_SystemCustomization\" Icon=\"/_imgs/area/18_syscust.gif\" Url=\"/tools/systemcustomization/systemcustomization.aspx\" Client=\"Web\" /&gt;&lt;/Group&gt;&lt;/Area&gt;&lt;/SiteMap&gt;</sitemapxml>
<campaignprefix>CMP</campaignprefix><currentbulkoperationnumber formattedvalue=\"1,000\">1000</currentbulkoperationnumber><allowmarketingemailexecution>0</allowmarketingemailexecution><minoutlooksyncinterval formattedvalue=\"15\">15</minoutlooksyncinterval>
   <allowautoresponsecreation>1</allowautoresponsecreation><grantaccesstonetworkservice>1</grantaccesstonetworkservice><schemanameprefix>New</schemanameprefix><allowautounsubscribe>0</allowautounsubscribe><businessclosurecalendarid>{00EC954A-6970-DB11-A6D4-0003FFD01F84}</businessclosurecalendarid>
   <sqlaccessgroupid>{A77C84E5-D14D-4F05-B099-0187C58AA74F}</sqlaccessgroupid><modifiedby name=\"Joe Administrator\" dsc=\"0\">{F45C6844-6970-DB11-A6D4-0003FFD01F84}</modifiedby>
   <currentcampaignnumber formattedvalue=\"1,008\">1008</currentcampaignnumber><bulkoperationprefix>BO</bulkoperationprefix><tagpollingperiod formattedvalue=\"600,000\">600000</tagpollingperiod><ignoreinternalemail>0</ignoreinternalemail>
</result>
</resultset>"
      */
      public void LoadFromResultSetXml(string xmlData)
      {
         XmlDocument    doc = new XmlDocument();

         doc.LoadXml(xmlData);
         XmlNode     nodeRoot = doc.DocumentElement;
         XmlNode     nodeResultSet = nodeRoot.ChildNodes[0];
         LoadFromXmlNode(nodeResultSet);
      }

      public void LoadFromXmlNode(XmlNode nodeRoot)
      {              
         foreach (XmlNode nodeItem in nodeRoot.ChildNodes)
         {            
            switch (nodeItem.Name)
            {
               case "currencyformatcode":               
                  this.CurrencyFormatCode = Convert.ToInt32(nodeItem.InnerText);
                  break;

               case "currencysymbol":               
                  this.CurrencySymbol = nodeItem.InnerText;
                  break;

               case "organizationid":               
                  this.OrganizationId = new Guid(nodeItem.InnerText);
                  break;

            }     

         } // end foreach      
      }

      public void LoadFromCrmOrganization(organization objCrmOrg)
      {
         this.CurrencyFormatCode = objCrmOrg.currencyformatcode.Value;
         this.CurrencySymbol = objCrmOrg.currencysymbol;
         this.OrganizationId = objCrmOrg.organizationid.Value;
      }

	} // end class
}
